<template>
	<view class="content" style="background-color: #fff;">
		<u-navbar bgColor="#DD2131" scrollable=false leftIconColor='#fff'
			titleStyle="font-size:40rpx;color:#333;color:#fff" :placeholder='true' title="我的钱包" :autoBack="true">
			<view class="u-nav-slot cof" slot="right" @click="go('/pages/my/wallet/bill')">
				账单
			</view>
		</u-navbar>
		<view class="top">
			<view class="left">
				<view>余额(元)</view>
				<view class="p">{{balance}}</view>
			</view>
			<view class="right" @click="go('/pages/my/wallet/withdrawal')">
				提现
			</view>
		</view>
		<view class="center" v-if="false">
			<view class="add ">
				充值
			</view>
			<view class="number">
				<view class="li">
					<view class="fw7 fontS28 co3" :class="item.checked==true?'checked':''" v-for="(item,index) in list"
						@click="check(item,index)">
						充{{item.value}}元
					</view>
				</view>
			</view>
			<button class="btn " @click="show = true">充值</button>
		</view>
		<view class="up">
			<u-popup :show="show" @close="close" @open="open" customStyle="padding:0 40rpx" :round='10'
				:closeable='true'>
				<view style="padding-top: 60rpx;">
					<view class="show_top" style="width: 100%;">
						<view class="top_li2" style="width: 100%;">
							<view class="">
								充值
							</view>
							<view class="money">
								￥{{money}}
							</view>
							<view class="">
							</view>
						</view>
						<view class="top_li3">
							<view class="li" style="margin-top: 20rpx;">
								<view class="u_radio">
									<u-radio-group v-model="radiovalue1" iconPlacement="right" placement="column"
										@change="groupChange">
										<view v-for="(item, index) in value" style="margin-bottom:86rpx;" :key=" index">

											<image :src="item.image" mode="" class="pagImage"></image>
											<u-radio :customStyle=" {marginTop: '5px' }" activeColor='#DD2131'
												:label=" item.name" :name="item.name" @change="radioChange">
											</u-radio>
										</view>
									</u-radio-group>
									<!-- <button class="redbtn">123</button> -->
									<u-button :loading='loading' @click="submit()" class="redbtn" >确认</u-button>
								</view>
							</view>
						</view>
					</view>
				</view>
			</u-popup>
		</view>
	</view>
</template>



<script>
	export default {
		onLoad() {
			// 获取用户个人信息
			this.$my.get('/index/user/get_user_info').then(res=>{
				if(res.code==200){
				   this.balance=res.data.balance.balance
				   uni.setStorageSync('userInfo',res.data)
				   uni.setStorageSync('phone',{phone:res.data.phone,area:res.data.phone_prefix})
				}
			})
		},
		data() {
			return {
				balance:"",
				value: [{
						name: '易宝支付',
						disabled: false,
						type: 1,
						image: '/static/images/mine/yipay.png'
					},
					{
						name: '支付宝支付',
						disabled: false,
						type: 2,
						image: '/static/images/mine/zhifubao.png'
					},
					{
						name: 'ApplePay',
						disabled: false,
						type: 3,
						image: '/static/images/mine/Group 33278.png'
					}, {
						name: '微信支付',
						disabled: false,
						type: 4,
						image: '/static/images/mine/weixin.png'
					}
				],
				list: [{
						value: '100',
						checked: true
					},
					{
						value: '200',
						checked: false
					},
					{
						value: '500',
						checked: false
					},
					{
						value: '1000',
						checked: false
					},
					{
						value: '5000',
						checked: false
					},
					{
						value: '10000',
						checked: false
					}
				],
				radiovalue1: '易宝支付',
				show: false,
				type: 1, //充值类型1易宝2支付宝 applepay4微信
				money: 100,
				loading:false,
			}
		},

		methods: {
			change(e) {
				console.log('change', e);
			},
			change2(e) {
				console.log('change', e);
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			groupChange() {
				// console.log('groupChange');
			},
			radioChange(name) {
				console.log('radioChange', name);
				switch (name) {
					case '易宝支付':
						this.type = 1;
						console.log("1,易宝支付", this.type);
						break;
					case '支付宝支付':
						this.type = 2;
						console.log("2,支付宝支付", this.type);
						break;
					case 'ApplePay':
						this.type = 3;
						console.log("3,ApplePay", this.type);
						break;
					case '微信支付':
						this.type = 4;
						console.log("4,微信支付", this.type);
						break;
					default:
						break;
				}

			},
			go(url) {
				uni.navigateTo({
					url
				})
			},
			check(item) {
				for (let s of this.list) {
					s.checked = false
				}
				item.checked = true
				this.money = item.value
			},
			// 确认充值
			submit() {
				this.loading=true
				// console.log(this.type, '金额', this.money);
				this.$my.post('/index/user_balance/recharge', {
					money: this.money,
					type: this.type
				}).then(res=>{
					console.log(res);
					if(res.code==200){
						if(res.code==200){
							this.$my.toast(res.message)
							this.loading=false
							this.$my.go('/pages/my/wallet/success?type=2',500)
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.checked {
		color: $red;
		border: 2rpx solid red !important;
	}

	.content {
		.pagImage {
			margin-right: 16rpx;
			margin-top: 10rpx;
			float: left;
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			background-color: #d9d9d9;
		}

		.redbtn {
			background-color: $red;
			color: white;
		}

		.top {
			// width: 100%;
			height: 200rpx;
			display: flex;
			justify-content: space-between;
			padding: 0 4%;
			border-bottom: 2rpx solid #ebebeb;
			background-color: $red;

			.left {

				view {
					font-size: 28rpx;
					line-height: 100rpx;
					color: #fff;
				}

				.p {
					font-size: 64rpx;

					line-height: 40rpx;
					color: #fff;
				}
			}

			.right {
				line-height: 200rpx;
				color: #fff;
			}

		}

		.center {
			font-size: 32rpx;
			// width: 100%;
			padding: 0 4%;
			background-color: #f5f5f5;

			.add {
				text-align: left;
				font-weight: bold;
				padding: 24rpx 0;
			}

			.number {
				>.li {
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;
					width: 100%;

					view {
						border: 2rpx solid transparent;
						border-radius: 8rpx;
						line-height: 100rpx;
						width: 30%;
						height: 100rpx;
						background-color: white;

						&:nth-child(1) {
							margin-bottom: 20rpx;
						}
					}
				}
			}

			.btn {
				border-radius: 46rpx;
				margin-top: 60rpx;
				background-color: $red;
				color: white;
				font-weight: bold;
			}
		}

		.up {
			.show_top {
				.top_li2 {
					// margin-top: 50rpx;
					// background-color: red;
					border-bottom: 2rpx solid #f5f5f5;
					height: 120rpx;
					display: flex;
					justify-content: space-between;

					view {
						width: 30%;
						line-height: 100rpx;
					}

					.money {
						font-size: 48rpx;
						font-weight: bold;
					}
				}

				.top_li3 {
					>.li {
						display: flex;
						padding-top: 20rpx;

						.u_radio {
							width: 100%;

						}
					}
				}
			}
		}
	}
</style>
